/*
 * Funny Language - a free style programming language.
 * Copyright (C) 2015 by fanguangping (fanguangping@163.com)
 * state.c
 */

#include <stdlib.h>
#include <stdio.h>
#include "state.h"
#include "../base/constants.h"
#include "../base/cmemory.h"

static int stateId = 0;

State *alloc_state() {
	return (State *) sys_malloc(sizeof(State));
}

State *new_state() {
	State *s = alloc_state();
	s->id = stateId++;
	s->accept = FALSE;
	return s;
}

int equals_state(void *a, void *b) {
	if (a == NULL && b == NULL)
		return TRUE;
	if (a == NULL || b == NULL)
		return FALSE;
	return ((State *) a)->id == ((State *) b)->id;
}

int hash_code_state(void *s) {
	if (s == NULL)
		return -1;
	return (((State *) s)->id) % HASHTABLE_SIZE;
}

